import random


class Students:
    def __init__(self, sid, name, age):
        self.sid = sid
        self.name = name
        self.age = age

    def __str__(self):
        return f'学号：{self.sid} 姓名：{self.name} 年龄：{self.age}'


class StudentsMange:
    def __init__(self):
        self.ls = []

    def add_student(self):
        name = ['小李', '小王', '小吴', '小马', '小米', '小龙', '小陈', '小谢', '小胡', '小唐']
        for i in range(10):
            s = Students(101 + i, f"{name[i]}", f"{random.randint(18, 20)}")
            d = {"sid": s.sid, "name": s.name, "age": s.age}
            self.ls.append(d)

    def show_student(self):
        for i in self.ls:
            print(i)

    def sort_age(self):
        for i in range(len(self.ls)-1):
            max_index = i
            for j in range(i+1, len(self.ls)):
                if self.ls[max_index]["age"] > self.ls[j]["age"]:
                    max_index = j
            if max_index != i:
                age = self.ls[max_index]
                self.ls[max_index] = self.ls[i]
                self.ls[i] = age

    def sort_sid(self):
        for i in range(len(self.ls) - 1):
            for j in range(i + 1, len(self.ls)):
                if self.ls[i]["age"] == self.ls[j]["age"] and self.ls[i]["sid"] < self.ls[j]["sid"]:
                    sid = self.ls[j]
                    self.ls[j] = self.ls[i]
                    self.ls[i] = sid


def main():
    stud = StudentsMange()
    stud.add_student()
    stud.sort_age()
    stud.sort_sid()
    stud.show_student()


main()
